/*
 * @Author       : NaN 353362604@qq.com
 * @Date         : 2023-07-10 10:34:33
 * @LastEditTime : 2023-08-14 17:09:01
 * @LastEditors  : NaN 353362604@qq.com
 * @FilePath     : \AdminStration\src\Pages\Front\Assets\Common\Common.jsx
 * @Description  :
 */
import './Scss/Common.scss'
import dayjs from 'dayjs'
import { Tooltip } from 'antd'
import { useNavigate } from 'react-router-dom'
import { useState, useEffect } from 'react'
import { useTitle, useFavicon } from 'ahooks'
import { ConsoleSqlOutlined, LogoutOutlined } from '@ant-design/icons'

export const BasicSettings = ({ title, imageUrl }) => {
    useTitle(title)
    useFavicon(imageUrl + 'Ico.ico')
}

export const RouterSlice = path => {
    const [, , two, thr] = path.split('/')
    return { two, thr }
}

// 标准导航
export const RouterHandle = (path, list) => {
    const [, , , thr] = path.split('/')
    if (thr) {
        const { title, child } = list.find(v => v.path === thr.slice(0, 3))
        return { url: thr, title, child }
    }
}

// 标准导航(长期支持)
export const RouterHandleA01 = (path, list) => {
    const [, , , thr] = path.split('/')
    if (thr) {
        const { title, child } = list.find(v => v.path === thr.slice(0, 1))
        return { url: thr, title, child }
    }
}

// 时间
export const Time = ({ one, two }) => {
    const [now, setNow] = useState(dayjs())
    useEffect(() => {
        const t = setInterval(() => setNow(dayjs()), 1000)
        return () => clearTimeout(t)
    }, [])
    return (
        <div>
            {one && <span className="one">{now.format(one)}</span>}
            {two && <span className="two">{now.format(two)}</span>}
        </div>
    )
}

// 操作项
export const TopSwitch = ({ one, two }) => {
    const Navigate = useNavigate()
    return (
        <div className="TopSwitch">
            <Tooltip title="进入后台" zIndex={10000} onClick={() => Navigate('/Admin')}>
                <ConsoleSqlOutlined style={{ color: 'white', fontSize: 20 }} />
                <span>{one}</span>
            </Tooltip>
            <Tooltip title="退出登录" zIndex={10000} onClick={() => Navigate('/')}>
                <LogoutOutlined style={{ color: 'white', fontSize: 20 }} />
                <span>{two}</span>
            </Tooltip>
        </div>
    )
}
